'use strict';
import 'normalize.css'
import './assets/font/iconfont.css'
import './scss/common.scss'
import './scss/applicationList.scss'
import './scss/applicationDetails.scss'
import './assets/lib/jqueryVaildate/dist/jquery.validate.min'
import './js/vertiy'
import '../node_modules/swiper/dist/css/swiper.min.css'

import Swiper from 'swiper'
import HeaderDropdown from './js/HeaderDropdown'
import ApiRadioGroup from './js/ApiRadioGroup'
import ScrollHeader from './js/ScrollHeader'
import Tab from './js/Tab';
import LoginForm from './js/LoginForm'
import RegisterForm from './js/RegisterForm'


$(function () {

    $('a[data-toggle="headerDropDown"]').each(function (index, item) {
        new HeaderDropdown(item)
    });

    $('div[data-toggle="apiRadioGroup"]').each(function (index, item) {
        new ApiRadioGroup(item, {
            change: (value, label, $apiRadio, $element) => {
                const $apiPriceBar = $element.next();
                $apiPriceBar.find('.price').text('¥' + value);
                $apiPriceBar.find('.remark').text($apiRadio.data('remark') || '');
                $apiPriceBar.find('.single-price').text(label ? (value / label).toFixed(5) : 0)
            }
        })
    });

    $('div[data-toggle="scrollHeader"]').each(function (index, item) {
        new ScrollHeader(item);
    });

    $('[data-toggle="apiTab"]').each(function (index, item) {
        //实例代码，  生成promise 对象， 延迟300毫秒出现， 可以发送ajax请求
        new Tab(item, {
            beforeShow(e) {
                return new Promise((resolve, reject) => {
                    if ($(e.target).data('code')) {
                        setTimeout(() => {
                            resolve()
                        }, 300)
                    } else {
                        resolve()
                    }
                })
            }
        });
    })

    new LoginForm($('#loginForm'));
    new RegisterForm($('#userNameForm'));

    const indexSwiper = new Swiper('#swiperContainer', {
        direction: 'vertical',
        mousewheel: true,
        autoHeight: true,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        on: {
            init () {
               const $swiperSlide = this.$el.find('.swiper-slide')
                const swiperHeight = $swiperSlide.css('height');
                $swiperSlide.find('.sws-content').css('height', swiperHeight)
            },
            resize(){
                const $swiperSlide = this.$el.find('.swiper-slide')
                const swiperHeight = $swiperSlide.css('height');
                $swiperSlide.find('.sws-content').css('height', swiperHeight)
            }
        }
    })

    $('.toggle-register-way').on('click', (e) => {
        e.stopPropagation();
        e.preventDefault();
        const $parentForm = $(e.target).parents('form');
        $parentForm.hide().siblings().show();

        //需要清空数据重新
    })


});